home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / muzsrc1.zip / INDEXED.CPP < prev    next >
C/C++ Source or Header  |  1992-07-21  |  2KB  |  70 lines

  1. // **********************************************
  2. // File: INDEXED.CPP
  3. // IndexedList is an extension of the Array class
  4. // with capabilities to insert and delete at specific places
  5. // This module contains the functions for processing
  6. // requests concerning this class.
  7.  
  8. #include "muzika.h"
  9.  
  10. // **********************************************
  11. // IndexedList::insertAt inserts a given object at the
  12. // specified index. All objects at subsequent indexed are
  13. // moved one index forward.
  14.  
  15. void IndexedList :: insertAt(Object &obj, int index)
  16. {
  17.   if (itemsInContainer > 0) {
  18.     // There are items in the list;
  19.     // reallocate if necessary and insert the object
  20.     // at the specified index
  21.     if (upperbound < itemsInContainer)
  22.       reallocate(itemsInContainer+1);
  23.     insertEntry(index);
  24.     setData(index, &obj);
  25.   }
  26.   else
  27.     // List is empty: just use the Array class's addAt function
  28.     addAt(obj, 0);
  29.   lastElementIndex = itemsInContainer++;
  30. }
  31.  
  32. // **********************************************
  33. // IndexedList::detachAt removes an entry from the
  34. // specified index without destroying the object. Subsequent
  35. // entries are pulled one index down.
  36.  
  37. void IndexedList :: detachAt(int index)
  38. {
  39.   // Check the the index is valid, then use the Array class's
  40.   // detach function
  41.   if (index < lowerbound+itemsInContainer)
  42.     detach(index);
  43. }
  44.  
  45. // **********************************************
  46. // IndexedList::destroyAt removes an entry from the
  47. // specified index and destroys the object. Subsequent
  48. // entries are pulled one index down.
  49.  
  50. void IndexedList :: destroyAt(int index)
  51. {
  52.   // Check that the index is valid, then use the Array class's
  53.   // destroy function
  54.   if (index < lowerbound+itemsInContainer)
  55.     destroy(index);
  56. }
  57.  
  58. // **********************************************
  59. // IndexedList::printOn prints the contents of the list
  60. // on the specified stream by calling the contained objects'
  61. // printOn functions. This function is used for saving a melody
  62. // in a file.
  63.  
  64. void IndexedList :: printOn(ostream &out) const
  65. {
  66.   // Call the contained objects' printOn functions
  67.   for (int index = lowerbound; index < lowerbound+itemsInContainer; ++index)
  68.     objectAt(index).printOn(out);
  69. }
  70.